package com.play.trading_test.mq;

import jakarta.annotation.Resource;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty("rocketmq.name-server")
public class MessageProducer {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public void sendDelayMessage(String topic, String message, int delay) {
        rocketMQTemplate.syncSend(topic, new GenericMessage<>(message), 3000, delay);
    }

    public void sendMessage(String topic, String message) {
        rocketMQTemplate.syncSend(topic, new GenericMessage<>(message));
    }

}
